﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class TonGiaoInfo
    {
        private string _TonGiaoID;

        public string TonGiaoID
        {
            get { return _TonGiaoID; }
            set { _TonGiaoID = value; }
        }

        private string _TenTonGiao;

        public string TenTonGiao
        {
            get { return _TenTonGiao; }
            set { _TenTonGiao = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class TonGiaoCtr
    {
        string strCnn = DBClass_Local.GetConnectString();

        public void Insert(TonGiaoInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TonGiaoID", Item.TonGiaoID),
                new SqlParameter("@TenTonGiao", Item.TenTonGiao == null ? (object)DBNull.Value:Item.TenTonGiao),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TonGiao_Insert", Para);
        }

        public void Update(TonGiaoInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TonGiaoID", Item.TonGiaoID),
                new SqlParameter("@TenTonGiao", Item.TenTonGiao == null ? (object)DBNull.Value:Item.TenTonGiao),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TonGiao_Update", Para);
        }

        public void Delete(string strTonGiaoID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TonGiaoID", strTonGiaoID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TonGiao_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_TonGiao_GetList");
            return Ds.Tables[0];
        }

        public TonGiaoInfo GetByID(string TonGiaoID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_TonGiao_Get", new SqlParameter("TonGiaoID", TonGiaoID));
            TonGiaoInfo ObjTonGiao = null;
            while (dtr.Read())
            {
                ObjTonGiao = new TonGiaoInfo();
                ObjTonGiao.TonGiaoID = dtr["TonGiaoID"].ToString();
                ObjTonGiao.TenTonGiao = dtr["TenTonGiao"].ToString();
                ObjTonGiao.Active = (bool)dtr["Active"];
            }
            return ObjTonGiao;
        }
    }
}
